package com.icow.wms.basic.controller;

import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.icow.common.annotation.Log;
import com.icow.common.core.controller.BaseController;
import com.icow.common.core.domain.AjaxResult;
import com.icow.common.enums.BusinessType;
import com.icow.wms.basic.domain.AgvErrorInfo;
import com.icow.wms.basic.service.IAgvErrorInfoService;
import com.icow.common.utils.poi.ExcelUtil;
import com.icow.common.core.page.TableDataInfo;

/**
 * agvErrorInfoController
 *
 * @author bcs
 * @date 2024-08-23
 */
@Slf4j
@RestController
@RequestMapping(value = {"/wcs/agvErrorInfo", "/api/peripheral"})
public class AgvErrorInfoController extends BaseController {
    @Autowired
    private IAgvErrorInfoService agvErrorInfoService;

    /**
     * 查询agvErrorInfo列表
     */
    @PreAuthorize("@ss.hasPermi('wcs:agvErrorInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AgvErrorInfo agvErrorInfo) {
        startPage();
        List<AgvErrorInfo> list = agvErrorInfoService.selectAgvErrorInfoList(agvErrorInfo);
        return getDataTable(list);
    }

    /**
     * 导出agvErrorInfo列表
     */
    @PreAuthorize("@ss.hasPermi('wcs:agvErrorInfo:export')")
    @Log(title = "agvErrorInfo", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AgvErrorInfo agvErrorInfo) {
        List<AgvErrorInfo> list = agvErrorInfoService.selectAgvErrorInfoList(agvErrorInfo);
        ExcelUtil<AgvErrorInfo> util = new ExcelUtil<AgvErrorInfo>(AgvErrorInfo.class);
        return util.exportExcel(list, "agvErrorInfo");
    }

    /**
     * 获取agvErrorInfo详细信息
     */
    @PreAuthorize("@ss.hasPermi('wcs:agvErrorInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(agvErrorInfoService.selectAgvErrorInfoById(id));
    }

    /**
     * 新增agvErrorInfo
     */
    @PreAuthorize("@ss.hasPermi('wcs:agvErrorInfo:add')")
    @Log(title = "agvErrorInfo", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AgvErrorInfo agvErrorInfo) {
        return toAjax(agvErrorInfoService.insertAgvErrorInfo(agvErrorInfo));
    }

    /**
     * 修改agvErrorInfo
     */
    @PreAuthorize("@ss.hasPermi('wcs:agvErrorInfo:edit')")
    @Log(title = "agvErrorInfo", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AgvErrorInfo agvErrorInfo) {
        return toAjax(agvErrorInfoService.updateAgvErrorInfo(agvErrorInfo));
    }

    /**
     * 删除agvErrorInfo
     */
    @PreAuthorize("@ss.hasPermi('wcs:agvErrorInfo:remove')")
    @Log(title = "agvErrorInfo", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(agvErrorInfoService.deleteAgvErrorInfoByIds(ids));
    }

    @ResponseBody
    @GetMapping("/deleteFinishTask")
    public void deleteFinishTask() {
        agvErrorInfoService.deleteThirtyDaysAgoData();
        log.info("Delete agv error info from thirty days ago");
    }
}